package com.hk.controller;

import cn.hutool.json.JSONUtil;
import com.hk.Enume.OperationType;
import com.hk.annotation.AotoFile;
import com.hk.constant.LogConstaant;
import com.hk.core.PageResult;
import com.hk.core.R;
import com.hk.core.Result;
import com.hk.domain.Clue;
import com.hk.dto.ClueDto;
import com.hk.dto.ClueUpdateDto;
import com.hk.dto.CluePageDto;
import com.hk.dto.PullDto;
import com.hk.service.ClueService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/clues")
public class ClueController {
    @Autowired
    ClueService clueService;
    /**
     * 新增线索
     */
    @PostMapping("/clue")

    public R addClue(@RequestBody ClueDto dto){
        clueService.add(dto);
        return R.ok();
    }

    /**
     * 查看线索列表
     */
    @GetMapping("/clue/list")
    public PageResult list(CluePageDto dto){
      PageResult res=clueService.list(dto);
        return res;
    }

    /**
     * 根据ID查看线索表
     */
    @GetMapping("/clue/{id}")
    public R<Clue> queryByid(@PathVariable Integer id){
      Clue vo= clueService.queryById(id);
      return R.ok(vo);
    }

    /**
     * 修改线索表和线索历史表
     */
    @PostMapping("/record")
    public R updateClue(@RequestBody ClueUpdateDto dto){
        clueService.updateClue(dto);
        return R.ok();
    }
    /**
     * 根据线索id查看线索历史表
     */
    @GetMapping("/record/list")
    public PageResult listClueHistory(Integer clueId){
      PageResult res= clueService.listClueHistory(clueId);
      return res;
    }
    /**
     * 把线索表转为商机表
     */
    @AotoFile(value = OperationType.PUT,title = LogConstaant.CLUE_LOG)
    @PutMapping("/clue/changeBusiness/{id}")
    public R changeBusiness(@PathVariable Integer id){
        clueService.changeBusiness(id);
        return R.ok();
    }
    /**
     * 把线索推到线索池子
     */
    String JSON="{\"msg\":\"操作成功\",\"code\":200}";
    @AotoFile(value = OperationType.PUT,title = LogConstaant.CLUE_LOG)
    @PutMapping("/clue/false/{id}")
    public String push(@PathVariable Integer id){
     int i=clueService.push(id);
     return JSONUtil.toJsonStr(JSON);
    }

    //查询线索池
    @GetMapping("/clue/pool")
    public PageResult listPoll(CluePageDto dto){
        PageResult res=clueService.listPoll(dto);
        return res;
    }

    //从线索池拉线索
    @AotoFile(value = OperationType.PUT,title = LogConstaant.CLUE_LOG)
    @PutMapping("/clue/gain")
    public R pull(@RequestBody PullDto dto){
        clueService.pull(dto);
        return R.ok();
    }



}
